Fix
Fix and Truncate (x), Truncate (x, #places) are equivalent functions. However, Fix is preferred in Basic syntax whereas Truncate is preferred in Crystal syntax.
Overloads
- Fix (number)
- Fix (number, #places)
Arguments
- number is the Number value to be truncated; it can be positive, 0 or negative.
- #places is an optional Number indicating the number of decimal places to be truncated to. If omitted, 0 is assumed.
Returns
Whole number value which can be positive, 0 or negative.
Action
Fix truncates a number to the specified number of decimal places and returns it. If #places is omitted, 0 is assumed.
Examples
The following examples are applicable to both Basic and Crystal syntax:
Fix (123.678)
Returns 123.
Fix (-123.678)
Returns -123.
Fix (123.678,1)
Returns 123.6.
Fix (123.678,2)
Returns 123.67.
Comments
- This function with a single parameter, Fix (number), is designed to work like the Visual Basic function of the same name.
- Fix (n) and Int (number) work the same except when n is negative, in which case Fix returns the first integer greater than or equal to n, and Int returns the first integer smaller than or equal to n. For example,
Fix (-10.2)
Returns -10.
Int (-10.2)
Returns -11.